package lium.lbs.lbsim.adapter

import android.widget.TextView
import com.buz.hjcdriver.bean.FriendsModel
import com.buz.hjcdriver.bean.TelphoneResultModel
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.qmuiteam.qmui.widget.QMUIRadiusImageView
import lium.lbs.lbsim.R
import lium.lbs.lbsim.activity.GetTelNumberActivity
import lium.lbs.lbsim.jgchat.utils.photovideo.takevideo.utils.LogUtils
import lium.lbs.lbsim.utils.PinnedHeaderItemDecoration

/**
 * 好友 adapter
 */

class GetTelPhoneNumberAdapter
    (data: ArrayList<TelphoneResultModel>) : BaseMultiItemQuickAdapter<TelphoneResultModel, BaseViewHolder>(data),
    PinnedHeaderItemDecoration.PinnedHeaderAdapter {

    override fun isPinnedViewType(viewType: Int): Boolean {
        return viewType == FriendsModel.ITEM_TYPE_SETION
    }

    var getTelNumberActivity: GetTelNumberActivity? = null

    init {
        getTelNumberActivity = mContext as GetTelNumberActivity?
        addItemType(FriendsModel.ITEM_TYPE_DATA, R.layout.item_contact_telnumber)
        addItemType(FriendsModel.ITEM_TYPE_SETION, R.layout.item_list_setion)
    }

    override fun convert(helper: BaseViewHolder?, item: TelphoneResultModel?) {
        helper?.let {
            item?.let {
                when (helper.itemViewType) {
                    FriendsModel.ITEM_TYPE_DATA -> {
                        initData(helper, item)
                    }
                    FriendsModel.ITEM_TYPE_SETION -> {
                        helper.getView<TextView>(R.id.item_setion).text = item.letters + ""
                    }
                }
            }
        }
    }

    private fun initData(helper: BaseViewHolder, item: TelphoneResultModel) {
        helper.getView<TextView>(R.id.contacts_phone).text = item?.phone
        if(item?.isMember.equals("1")){
            helper.getView<TextView>(R.id.contacts_name).text = item?.nickName
        } else{
            helper.getView<TextView>(R.id.contacts_name).text = item?.name
        }
        getTelNumberActivity?.displayImage(
            item.headImage,
            R.drawable.icon_defalut_head,
            helper.getView<QMUIRadiusImageView>(R.id.contacts_myhead)

        )

    }

}